﻿<Window x:Class="SqlProcessViewer.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="SQL Process Viewer" Width="800" Height="600" Icon="/SqlProcessViewer;component/Resources/SQL.png">
    <Window.CommandBindings>
        <CommandBinding Command="Refresh" Executed="RefreshCommandBinding_Executed" />
    </Window.CommandBindings>
    
    <Window.Resources>
        <!--DataTemplate for HeaderTemplate Arrows-->
        <DataTemplate x:Key="HeaderTemplateArrowUp" >
            <DockPanel>
                <TextBlock HorizontalAlignment="Center" Text="{Binding}" />
                <Path x:Name="arrow" StrokeThickness="1" Fill="Gray" Data="M 5,10 L 15,10 L 10,5 L 5,10" />
            </DockPanel>
        </DataTemplate>
        
        <DataTemplate x:Key="HeaderTemplateArrowDown" >
            <DockPanel>
                <TextBlock HorizontalAlignment="Center" Text="{Binding}" />
                <Path x:Name="arrow" StrokeThickness="1" Fill="Gray" Data="M 5,5 L 10,10 L 15,5 L 5,5" />
            </DockPanel>
        </DataTemplate>
    </Window.Resources>
    
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="32" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        
        <ToolBar Grid.Row="0">
            <Button Command="Refresh">
                <Button.Content>
                    <StackPanel Orientation="Horizontal">
                        <Image Source="/SqlProcessViewer;component/Resources/Refresh.png" Margin="0,0,4,0" />
                        <TextBlock Text="Refresh" VerticalAlignment="Center" />
                    </StackPanel>
                </Button.Content>
            </Button>
            <Separator />
            <Label Content="{Binding Path=LastRefresh}" ContentStringFormat="Last refresh: {0:T}" VerticalContentAlignment="Center" />
            <Separator />
            <Label Content="{Binding Path=RunTime}" ContentStringFormat="Run time: {0}" VerticalContentAlignment="Center" />
        </ToolBar>

        <ListView Grid.Row="1" ItemsSource="{Binding}" GridViewColumnHeader.Click="ColumnHeader_Clicked">
            <ListView.View>
                <GridView>
                    <GridViewColumn Header="Server Process ID" DisplayMemberBinding="{Binding SPID}" />
                    <GridViewColumn Header="Status" DisplayMemberBinding="{Binding Status}" />
                    <GridViewColumn Header="Login" DisplayMemberBinding="{Binding Login}" />
                    <GridViewColumn Header="Host Name" DisplayMemberBinding="{Binding HostName}" />
                    <GridViewColumn Header="Blocked By" DisplayMemberBinding="{Binding BlkBy}" />
                    <GridViewColumn Header="DB Name" DisplayMemberBinding="{Binding DBName}" />
                    <GridViewColumn Header="Command" DisplayMemberBinding="{Binding Command}" />
                    <GridViewColumn Header="CPU Time" DisplayMemberBinding="{Binding CPUTime}" />
                    <GridViewColumn Header="Disk I/O" DisplayMemberBinding="{Binding DiskIO}" />
                    <GridViewColumn Header="Last Batch" DisplayMemberBinding="{Binding LastBatch}" />
                    <GridViewColumn Header="Program Name" DisplayMemberBinding="{Binding ProgramName}" />
                    <GridViewColumn Header="Request ID" DisplayMemberBinding="{Binding REQUESTID}" />
                </GridView>
            </ListView.View>
        </ListView>
    </Grid>
</Window>